package hust.ioic.oa.service.impl;

import java.util.List;

import javax.annotation.Resource;

import hust.ioic.oa.base.BaseDao;
import hust.ioic.oa.base.BaseDaoImpl;
import hust.ioic.oa.domain.MessageQuene;

import org.hibernate.Query;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import hust.ioic.oa.service.MessageQueneService;
@Service
@Transactional
@SuppressWarnings("unchecked")
public class MessageQueneServiceImpl extends BaseDaoImpl<MessageQuene>  implements MessageQueneService {

	@Override
	public List<MessageQuene> getMBySender(Integer operatorId) {
		// TODO Auto-generated method stub
		return getSession()//
				.createQuery("FROM MessageQuene m WHERE m.sendId=? and (m.status=? or m.status=? or m.status=?) order by id desc")//
				.setParameter(0, operatorId)
				.setParameter(1, 1)
				.setParameter(2, 2)
				.setParameter(3, 3)
				.list();
	}

	@Override
	public List<MessageQuene> getMByRecevier(Integer operatorId) {
		// TODO Auto-generated method stub
		return getSession()//
				.createQuery("FROM MessageQuene m WHERE m.recevieId=? and (m.status=? or m.status=?) order by id desc")//
				.setParameter(0, operatorId)
				.setParameter(1, 0)
				.setParameter(2, 4)
				.list();
	}

	@Override
	public void deleteByFile(Integer rdfileId) {
		 Query query = getSession().createSQLQuery("delete from z_messageQuene  where rdfileId='" + rdfileId+ "'");
		 query.executeUpdate();

	}




}
